using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.FileProviders;

namespace AJAXCore.Middleware {
  public static class ApplicationBuilderExtensions {
    public static IApplicationBuilder UseNodeModules(this IApplicationBuilder applicationBuilder, string root) {
      var path = Path.Combine(root, "node_modules");
      var fileProvider = new PhysicalFileProvider(path);

      var options = new StaticFileOptions();
      options.RequestPath = "/node_modules";
      options.FileProvider = fileProvider;

      applicationBuilder.UseStaticFiles(options);
      return applicationBuilder;
    }
  }
}
